
package com.eascs.crm.nsEditDetail.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.admin.o2o.internal.util.StatusContexts;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.crm.nsEditDetail.service.ManagementTdInfoService;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;

@Controller
@RequestMapping("/management/td")
public class ManagementTdInfoViewController extends BaseMasterViewController {
	private final Logger logger = LoggerFactory.getLogger(ManagementTdInfoViewController.class);

	@Autowired
	ManagementTdInfoService tdInfoService;
	@Autowired
	O2oLoanapplyService o2oLoanapplyService;

	@RequestMapping(value = "/list")
	public String managementTdInfoList(String loanapplyNo, @RequestParam(defaultValue="0") Integer showPage,String type) {
		String pageUrl = "/bank/account/mgr?";
		String[] titles = {"时间", "负债总额（万元）", "净利（万元）","年销售额(元)"};
		O2oLoanapplyEntity o2oLoanapplyEntity = o2oLoanapplyService.findById(loanapplyNo);
		PageResult<Object[]> pageResult = tdInfoService.page(loanapplyNo);

		Button update = null;
		//update.setPermissionCode("dczllrUpdateButton");

		Button del = null;
		//del.setPermissionCode("dczllrUpdateButton");
		//Button look = ButtonHelper.createOpenButton("查看", "/dcloan/baseInfo?billCode={1}");
		//look.setPermissionCode("dczllrUpdateButton");
		if(!"detail".equals(type)){
			if(StatusContexts.O2O_ZX_END.equals(o2oLoanapplyEntity.getWfType())){
				update = ButtonHelper.createAjaxButton("修改", "/management/td/rest/updatePage?id=", "UpdateInternalInfo");
				//update.setPermissionCode("dczllrUpdateButton");
				del = ButtonHelper.createAjaxConfirmButton("删除",  "/management/td/rest/del?id=", "UpdateInternalInfo");
				del.setConfirmMessage("确定删除?");
			}
		}
		Button[] detailButton = new Button[] {update, del};

		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl + "&showPage=");
		paginationInfo.setBuildPagingNavigation(false);
		paginationInfo.setMoreButtons(detailButton);
		paginationInfo.setBuildRowNumber(true);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setRendTo("#management");
		ViewContext.put("paginationInfo", paginationInfo);

		return "nsEditDetail/management_td_info_list";

	}

}
